import axios from 'axios'
import storage from '@/utils/storage'

let instance = axios.create({
  baseURL: 'http://127.0.0.1:8000/api/',
})

instance.interceptors.request.use(
  (config) => {
    let token = storage.getToken()
    if (token) {
      config.headers.Authorization = token
    }
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

instance.interceptors.response.use(
  (response) => {
    return response.data
  },
  (error) => {
    return Promise.reject(error)
  }
)

export default instance
